using System.ComponentModel.DataAnnotations;
using System.Data.Entity.ModelConfiguration;

namespace WeberTimeTracker.Models.Mapping
{
    public class TimeMap : EntityTypeConfiguration<Time>
    {
        public TimeMap()
        {
            // Primary Key
            this.HasKey(t => t.Time_ID);

            // Properties
            this.Property(t => t.Description)
                .IsRequired();

            // Table & Column Mappings
            this.ToTable("Times");
            this.Property(t => t.Time_ID).HasColumnName("Time_ID");
            this.Property(t => t.User_ID).HasColumnName("User_ID");
            this.Property(t => t.Project_ID).HasColumnName("Project_ID");
            this.Property(t => t.Hours).HasColumnName("Hours");
            this.Property(t => t.Date).HasColumnName("Date");
            this.Property(t => t.Description).HasColumnName("Description");
            this.Property(t => t.Paid).HasColumnName("Paid");
			this.Property(t => t.Invoiced).HasColumnName("Invoiced");

            // Relationships
            this.HasRequired(t => t.Project)
                .WithMany(t => t.Times)
                .HasForeignKey(d => d.Project_ID);
            this.HasRequired(t => t.User)
                .WithMany(t => t.Times)
                .HasForeignKey(d => d.User_ID);

        }
    }
}
